package io.renren.modules.sp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.annotation.SeasonFilter;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.constant.Constant;
import io.renren.modules.log.dto.SysLogErrorDTO;
import io.renren.modules.sp.dao.SpMatchAreaDao;
import io.renren.modules.sp.dto.SpMatchAreaDTO;
import io.renren.modules.sp.entity.SpMatchAreaEntity;
import io.renren.modules.sp.service.SpMatchAreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 省赛按地区控制可报赛项
 *
 * @author whc sunlightcs@gmail.com
 * @since 3.0 2024-06-16
 */
@Service
public class SpMatchAreaServiceImpl extends CrudServiceImpl<SpMatchAreaDao, SpMatchAreaEntity, SpMatchAreaDTO> implements SpMatchAreaService {

    @Override
    public QueryWrapper<SpMatchAreaEntity> getWrapper(Map<String, Object> params) {
        QueryWrapper<SpMatchAreaEntity> wrapper = new QueryWrapper<>();

        String matchId = (String) params.get("matchId");
        wrapper.eq(StringUtils.isNotBlank(matchId), "match_id", matchId);

        wrapper.orderByDesc("id");
        return wrapper;
    }

    @Override
    public PageData<SpMatchAreaEntity> selectPage(Map<String, Object> params) {
        Page page = createPage(params);
        //分页参数
        params.put(Constant.PAGE, page);
        IPage<SpMatchAreaEntity> page2 = this.baseDao.selectPage(page, params);
        PageData<SpMatchAreaEntity> pageData = new PageData(page2.getRecords(), page2.getTotal());
        return pageData;
    }


}
